package chapter6.meine.GUIexamples;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JApplet;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import chapter6.SubKillerPanel;

public class LabelWithSlidersAndBox extends JApplet{
	
	 public void init() {
	      setContentPane( new ContentPanel() );
	   }//end of init()
	
	public static class ContentPanel extends JPanel 
	implements ActionListener, ChangeListener{
		
		private JSlider bgColorSlider;
		private JSlider fgColorSlider;
		private JComboBox fontComboBox;
		private JLabel label;
		
		public ContentPanel(){
			
			label = new JLabel("Hello World");
			label.setOpaque(true);
			label.setBackground(new Color(0, 0, 0 ));
			label.setForeground(new Color(255, 255, 255 ));
			label.setFont( new Font("Serif", Font.BOLD, 30) );
			
			bgColorSlider = new JSlider(0, 255, 1);
			bgColorSlider.addChangeListener(this);
			
			fgColorSlider = new JSlider(0, 255, 1);
			fgColorSlider.addChangeListener(this);
			
			fontComboBox = new JComboBox();
			fontComboBox.addItem("Plain Font");
			fontComboBox.addItem("Italic Font");
			fontComboBox.addItem("Bold Font");
			fontComboBox.addItem("Bold Italic Font");
			fontComboBox.setSelectedIndex(2);
			fontComboBox.addActionListener(this);
			
			  setLayout(new GridLayout(4,1));
			  add(label);
			  add(bgColorSlider);
			  add(fgColorSlider);
			  add(fontComboBox);
		}// end of ContentPanel constructor

		@Override
		public void stateChanged(ChangeEvent evt) {
			if (evt.getSource()== bgColorSlider){
				int i = bgColorSlider.getValue();
				label.setBackground(new Color(i,i,i));
			}
			else {
				int j = fgColorSlider.getValue();
				label.setForeground(new Color(255,j,j));
			}
			
			
			// TODO Auto-generated method stub
			
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			   switch ( fontComboBox.getSelectedIndex()) {
		         case 0:
		            label.setFont( new Font("Serif", Font.PLAIN, 30) );
		            break;
		         case 1:
		            label.setFont( new Font("Serif", Font.ITALIC, 30) );
		            break;
		         case 2:
		            label.setFont( new Font("Serif", Font.BOLD, 30) );
		            break;
		         case 3:
		            label.setFont( new Font("Serif", Font.BOLD + Font.ITALIC, 30) );
		            break;
		         }
		      }
		
	}// end of class ContentPanel
	
	

}// end of class LabelWithSlidersAndBox
